package com.chinasofti.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chinasofti.bean.User;
import com.chinasofti.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Arrays;
import java.util.List;

@Controller
public class TableController {

    @Autowired
    private UserService userService;

    @GetMapping("/basic_table")
    public String basic_table(){//springboot会将对应的异常信息跳转到error文件夹下指定的页面
        int i = 1/0;
        System.out.println("i = " + i);
        return "table/basic_table";
    }
    //表格数据
    @GetMapping("/dynamic_table")
    public String dynamic_table(@RequestParam(value = "pn",defaultValue = "1")Integer pn, Model model){
//        List<User> users = Arrays.asList(new User("tom","123"),
//                new User("tom1","123"),
//                new User("tom2","123"),
//                new User("tom3","123"));
        //设置分页信息
        Page<User> page = new Page<>(pn,2);
        //根据分页信息进行查询
        Page<User> userPage = userService.page(page, null);

        model.addAttribute("users",userPage);
        return "table/dynamic_table";
    }
    @GetMapping("/responsive_table")
    public String responsive_table(){
        return "table/responsive_table";
    }
    @GetMapping("/editable_table")
    public String editable_table(){
        return "table/editable_table";
    }
}
